import { createSlice } from "@reduxjs/toolkit";

const userSlice = createSlice({
  name: "user",

  initialState: {
    // userInfo: {},
    adminname: "", // 用户名
    checkedkeys: [], // 左侧菜单权限
    role: null, // 角色 1 - 管理员 2 - 超级管理员
    token: "", // token
  },

  reducers: {
    setUserInfo(state, action) {
      state.adminname = action.payload.adminname;
      state.checkedkeys = action.payload.checkedkeys;
      state.role = action.payload.role;
      state.token = action.payload.token;
    },
  },
});

// 具名导出 reducer
export const { reducer } = userSlice;

// 具名到 actionCreator
export const { setUserInfo } = userSlice.actions;
